clear all
numIter = 1000;
period_labels = [10 30];

maxDetectPower = 0;
best_baseSeq = [];
best_probability_repetition = [];
best_transition_sequence = [];
best_strSeq = [];
best_fullSeq = [];
best_transSeq = [];
best_detectPower = [];


period_labels = [10 20 30];


for i=1:numIter
    % Generate sequence using a sinusoidal guide function with period=period_labels
    [baseSeq probability_repetition transition_sequence] = seqGen(7,period_labels);
    
    % Add zeros and targets
    [strSeq, fullSeq] = addZerosAndTargets(baseSeq);
    fullSeq = fullSeq(:);
    
    % Generate transition sequence
    transSeq = zeros(size(fullSeq));
    transSeq(1) = -1; % The first transition is invalid (blank to blank)
    for j=2:length(transSeq)
        if min(fullSeq(j),fullSeq(j-1)) < 1
            transSeq(j) = -1;
        else
            transSeq(j) = abs(fullSeq(j)-fullSeq(j-1));
        end
    end
    
    % Calculate detection power
    detectPower = evalSeq(transSeq,1600);
    
    if detectPower > 0.95*maxDetectPower
        %{
        display(baseSeq');
        display(probability_repetition);
        display(transition_sequence);
        display(strSeq);
        display(fullSeq);
        display(transSeq);
        %}
        
        best_baseSeq = [best_baseSeq baseSeq];
        best_probability_repetition = [best_probability_repetition probability_repetition'];
        best_transition_sequence = [best_transition_sequence transition_sequence'];
        best_strSeq = [best_strSeq strSeq(:)];
        best_fullSeq = [best_fullSeq fullSeq];
        best_transSeq = [best_transSeq transSeq];
        best_detectPower = [best_detectPower detectPower];
        
        display(detectPower)
        if detectPower > maxDetectPower
            maxDetectPower = detectPower;
        end
    end
    
end


save all